Historical updating oE format, Revision 2
format
include datetime.e namespace datetime public function format(datetime d, sequence pattern = "%Y-%m-%d %H:%M:%S")
formats the date according to the format pattern string.
Parameters:
- d : a datetime which is to be printed out
- pattern : a format string, similar to the ones sprintf uses, but with some Unicode encoding. The default is "%Y-%m-%d %H:%M:%S".
Returns:
A string, with the date d formatted according to the specification in pattern.
Comments:
Pattern string can include the following specifiers:
- %% -- a literal %
- %a -- locale's abbreviated weekday name (e.g., Sun)
- %A -- locale's full weekday name (e.g., Sunday)
- %b -- locale's abbreviated month name (e.g., Jan)
- %B -- locale's full month name (e.g., January)
- %C -- century; like %Y, except omit last two digits (e.g., 21)
- %d -- day of month (e.g, 01)
- %H -- hour (00..23)
- %I -- hour (01..12)
- %j -- day of year (001..366)
- %k -- hour ( 0..23)
- %l -- hour ( 1..12)
- %m -- month (01..12)
- %M -- minute (00..59)
- %p -- locale's equivalent of either AM or PM; blank if not known
- %P -- like %p, but lower case
- %s -- seconds since 1970-01-01 00:00:00 UTC
- %S -- second (00..60)
- %u -- day of week (1..7); 1 is Monday
- %w -- day of week (0..6); 0 is Sunday
- %y -- last two digits of year (00..99)
- %Y -- year
Note:
There is a format() function in std/text.e as well. Be sure to use the proper namespace if using both std/datetime.e and std/text.e
Example 1:
d = new(2008, 5, 2, 12, 58, 32) s = format(d, "%Y-%m-%d %H:%M:%S") -- s is "2008-05-02 12:58:32"
Example 2:
d = new(2008, 5, 2, 12, 58, 32) s = format(d, "%A, %B %d '%y %H:%M%p") -- s is "Friday, May 2 '08 12:58PM"
See Also:
Not Categorized, Please Help
|
- diff to current revision, view current revision history, backlinks
- Last modified Sep 06, 2019 by irv